home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MACD 5
/
MACD 5.bin
/
workbench
/
tools
/
czesc_3
/
psm
/
source
/
lists.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-28
|
1KB
|
61 lines
#include <exec/lists.h>
#include <exec/nodes.h>
void *num_to_node(struct List *lst,ULONG num)
{
struct Node *nd;
for(nd = lst->lh_Head;
nd != NULL && nd->ln_Succ != NULL && num > 0;
nd = nd->ln_Succ, num--) ;
if(nd == NULL || nd->ln_Succ == NULL) return NULL;
else return nd;
}
ULONG node_to_num(struct List *lst,void *nd)
{
struct Node *pos;
ULONG num = 0;
for(pos = lst->lh_Head;
pos != NULL && pos->ln_Succ != NULL && pos != (struct Node *)nd;
pos = pos->ln_Succ, num++) ;
if(pos == NULL || pos->ln_Succ == NULL) return ~0;
else return num;
}
void *head_node(struct List *lst)
{
if(lst == NULL || lst->lh_Head == NULL || lst->lh_Head->ln_Succ == NULL)
return NULL;
return lst->lh_Head;
}
void *tail_node(struct List *lst)
{
if(lst == NULL || lst->lh_TailPred == NULL || lst->lh_TailPred->ln_Pred == NULL)
return NULL;
return lst->lh_TailPred;
}
void *next_node(void *nd)
{
if( nd == NULL || ((struct Node *)nd)->ln_Succ == NULL
|| ((struct Node *)nd)->ln_Succ->ln_Succ == NULL ) return NULL;
return ((struct Node *)nd)->ln_Succ;
}
void *prev_node(void *nd)
{
if( nd == NULL || ((struct Node *)nd)->ln_Pred == NULL
|| ((struct Node *)nd)->ln_Pred->ln_Pred == NULL ) return NULL;
return ((struct Node *)nd)->ln_Pred;
}